#ifndef __GAME_H__
#define __GAME_H__
#include "PreHeader.h"
#include "PreDefine.h"
#include "System\graphics.h"
#include "System\texture.h"

#include "ASprite.h"
#include "System\ScreenManager.h"
#include "System/touchInput.h"
#include "../StateMachine/StateMachine.h"
#include "GameObjectManager.h"
#include "ResManager.h"
#include "ItemManager.h"
#include "RobotFactory.h"
#include "FileSystem/IFileSystem.h"
#include "Cinematics/CinematicManager.h"
#include "Cinematics/Cinematic.h"
#include "ParticleSystem/CFpsParticleSystemSceneNode.h"
#include "TutorialManager.h"
#include "ParticleSystem/IFpsParticleSystemSceneNode.h"
#include "ParticleSystem/EffectPreset.h"

struct State
{
	enum 
	{
		GS_Gameplay,
		GS_Loading,
		GS_LevelEnd,
	};
};
class Font;
class CWriteMemory;
class ParticleHolder;
class ParticleHolderManager;
//class TextureManager;
class CGame: public StateMachine
{

public:
	CGame(void);
	~CGame(void);

	static float	GetGameplayTimeStep() { return m_bIsGameplayPaused ? 0 : m_gamePlayTimeStep ; }
	static float	m_gamePlayTimeStep;
	static bool		m_bIsGameplayPaused; // Saved

	void Initialize();
	void Release();
	eIPLUpdateStatus Update(unsigned long delta_t_miliseconds);
	void Paint();

	void PauseGame();
	void ResumeGame();
	void ExitGame();

	cGfx * _gfx;
	TextureManager *mp_TexMgr;

	int miFrameCounter;
	unsigned long miMilliTime,miLastMilliTime;


	void SaveData(); //bgbejan save/load
	void SaveDataToFile();
	void SaveDataToMemory();
	void SaveDataToFileFromMemory();

	void LoadData();
	void LoadDataFromFile();
	void LoadDataFromMemory();

	CTouchInput		moTouchInput;
private:
	
	ScreenManager* m_ScreenManager;
	

	void DispatchState(int depth, int mode);

	ASprite* interfaces_sprite;

	bool m_isLoadDone;
	

#include "StateMachine\States\State_Loading.h"
#include "StateMachine\States\State_Gameplay.h"
#include "StateMachine\States\State_LevelEnd.h"

public:
	Font* mp_Font;
	IFileSystem*			FileSystem;
	GameObjectManager*		m_objectManager;
	ResManager*				m_resManager;
	ItemManager*			m_itemManager;
	RobotFactory*			m_robotFactory;
	CinematicManager*		m_cinematicManager;
	TutorialManager*		m_tutorialManager;	
	inline ScreenManager* GetScreenManager() {return m_ScreenManager;}
	
	inline ASprite* GetInterfaceSprite() {return interfaces_sprite;}
	IFpsParticleSystemSceneNode* CloneObjectEffectType(ParticleHolder* parHolder, stringw particleSystem);
protected:
	CWriteMemory*	m_saveBuffer;
	array<CEffectPreset*> m_EffectsPresets;
};

extern CGame* gp_GameApp;
inline CGame* getGame(){ return gp_GameApp;}
inline CTouchInput& getTouchInput(){ return gp_GameApp->moTouchInput;}
inline DebugDraw& getDebugDraw(){ return gp_GameApp->m_objectManager->m_debugDraw;}
inline cGfx* getGfx(){ return gp_GameApp->_gfx;}
inline TextureManager* getTexMgr(){return gp_GameApp->mp_TexMgr;}
inline Font* getFont() {return gp_GameApp->mp_Font;}
inline IFileSystem* getFileSystem(){return gp_GameApp->FileSystem;}
inline GameObjectManager* GetGameObjectManager() {return gp_GameApp->m_objectManager;}
inline DebugDraw& GetDebugDraw() {return gp_GameApp->m_objectManager->m_debugDraw;}
inline ResManager* GetResManager() {return gp_GameApp->m_resManager;}
inline ItemManager* GetItemManager() {return gp_GameApp->m_itemManager;}
inline TutorialManager* GetTutorialManager() {return gp_GameApp->m_tutorialManager;}
inline RobotFactory* GetRobotFactory() {return gp_GameApp->m_robotFactory;}
b2Vec2 ConvertScreenToWorld(int32 x, int32 y);




#endif
